/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package test_autoencode;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * OutputSoaker. Because programs don't like it when you keep them waiting.
 *
 * It's purpose is to soak up any output immediately from the executing program
 * so it doesn't get stuck in a lock (or even deadlock) waiting for it's
 * output buffer to be cleared.
 *
 * Program output is stored in a buffered reader. We can worry about printing it
 * at our own pace.
 * @author Raiscan
 */
public class OutputSoaker implements Runnable {
    String name;
    InputStream is;
    Thread thread;
    public OutputSoaker (String name, InputStream is)
    {
        this.name = name;
        this.is = is;
    }
public void start() {
        thread = new Thread(this);
        thread.start();
}
    public void run() {
        try {
            InputStreamReader isr = new InputStreamReader (is);
            BufferedReader br = new BufferedReader (isr);

        while (true)
        {
            String s = br.readLine();
            if (s == null)
                break;
            System.out.println("["+name+"] "+s);
        }
            is.close();
        }
        catch (Exception e)
        {

        }
    }
}
